package com.njwb.day07;

import java.util.Arrays;

public class StringPractice {

    public static String sortCharacters(String input) {
        char[] chars = input.toCharArray();
        Arrays.sort(chars);
        return new String(chars);
    }


    public static int countChar(String input, char target) {
        int count = 0;
        for (int i = 0; i < input.length(); i++) {
            if (input.charAt(i) == target) {
                count++;
            }
        }
        return count;
    }


    public static String[] splitAndSort(String input, String delimiter) {
        String[] parts = input.split(delimiter);
        Arrays.sort(parts);
        return parts;
    }


    public static void main(String[] args) {

        String str1 = "cbadwighckw";
        String sortedStr = sortCharacters(str1);
        System.out.println("排序后的字符串: " + sortedStr);


        String str2 = "adfadfsadfsdf";
        char targetChar = 'a';
        int count = countChar(str2, targetChar);
        System.out.println("字符 '" + targetChar + "' 出现的次数: " + count);


        String str3 = "华山-衡山-庐山-泰山-嵩山";
        String[] sortedMountains = splitAndSort(str3, "-");
        System.out.println("分割并排序后的结果: " + Arrays.toString(sortedMountains));
    }
}
